//== SAGITTARIUS ============================================================================

//== BEGINNING OF CODE ===============================================================

#include "sagittarius/core/SagittariusCore.h"
#include "sagittarius/parallel/clone.h"

//#define _GNU_SOURCE
#define __USE_GNU
#include <unistd.h>
#include <time.h>
#include <sys/time.h>
#include <sys/syscall.h>
#include <sched.h>
#include <errno.h>

int sg_clone(int (*fn)(void *), void* child_stack, int flags, void *arg) {
    pid_t m;
    pid_t n;
    m = syscall(SYS_gettid);
    n = syscall(SYS_clone, flags, child_stack);
    //AT(0);
    if(syscall(SYS_gettid) != m)
        return fn(arg);
    else
        return n;
}